package com.zzqstart.userservice.controller.remote.provide;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zzqstart.commonutils.JwtUtils;
import com.zzqstart.commonutils.R;
import com.zzqstart.userservice.entity.UcenterMember;
import com.zzqstart.userservice.service.UcenterMemberService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * ClassName: UcenMemberRemoteController
 * Package: com.zzqstart.userservice.controller.remote
 * Description:
 *
 * @Author zzqstart
 * @Create 2023-03-06 22:29
 * @Version 1.0
 */
@RestController
@RequestMapping("/userservice/member/remote")
@Api(tags = "用户管理中心——远程方法")
public class UcenMemberRemoteController {

    @Autowired
    private UcenterMemberService ucenterMemberService;

    @GetMapping("/index")
    public List<UcenterMember> getMemberList(){
        QueryWrapper<UcenterMember> wrapper = new QueryWrapper<>();
        //todo：不用时间排序
        wrapper.orderByDesc("create_time");
        wrapper.last("limit 8");
        List<UcenterMember> list = ucenterMemberService.list(wrapper);
        return list;
    }

    @ApiOperation(value = "通过MemberId获取用户信息")
    @GetMapping("/getMemberInfoByMemberId/{memberId}")
    public UcenterMember getMemberInfoByMemberId(@PathVariable("memberId") String memberId){
        UcenterMember ucenterMember = ucenterMemberService.getMemberById(memberId);
        return ucenterMember;
    }

    @ApiOperation(value = "通过用户名获取Id")
    @GetMapping("/getMemberIdByMemberName/{memberName}")
    public String getMemberIdByMemberName(@PathVariable("memberName") String memberName){
        QueryWrapper<UcenterMember> wrapper = new QueryWrapper<>();
        wrapper.eq("nickname",memberName);
        wrapper.select("id");
        UcenterMember member = ucenterMemberService.getOne(wrapper);
        return member.getId();
    }
}
